package biz.obake.team.touchprotector.features.shake;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
import androidx.appcompat.app.c;
import biz.obake.team.touchprotector.R;
import biz.obake.team.touchprotector.g.c;
import java.util.Locale;

public class ShakeActivity extends c implements SharedPreferences.OnSharedPreferenceChangeListener, c.b {
    private TextView t;
    private TextView u;
    /* access modifiers changed from: private */
    public SeekBar v;
    private Switch w;
    private long x = 0;
    private float y = 0.0f;

    class a implements SeekBar.OnSeekBarChangeListener {
        a() {
        }

        public void onProgressChanged(SeekBar seekBar, int i, boolean z) {
            float parseFloat = (Float.parseFloat(biz.obake.team.touchprotector.g.a.l("shake_sensitivity_max")) * ((float) (i + 1))) / ((float) (ShakeActivity.this.v.getMax() + 1));
            biz.obake.team.touchprotector.g.a.r("shake_sensitivity", String.format(Locale.US, "%.1f", new Object[]{Float.valueOf(parseFloat)}));
        }

        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    }

    class b implements CompoundButton.OnCheckedChangeListener {
        b(ShakeActivity shakeActivity) {
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            biz.obake.team.touchprotector.g.a.r("shake_sensitivity_max", z ? "10.0" : "4.0");
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:19:0x003c  */
    /* JADX WARNING: Removed duplicated region for block: B:22:? A[RETURN, SYNTHETIC] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void H(java.lang.String r5) {
        /*
            r4 = this;
            int r0 = r5.hashCode()
            r1 = -1065982837(0xffffffffc076648b, float:-3.8498867)
            r2 = 2
            r3 = 1
            if (r0 == r1) goto L_0x002a
            r1 = 1315611075(0x4e6aa1c3, float:9.8411744E8)
            if (r0 == r1) goto L_0x0020
            r1 = 1772712678(0x69a972e6, float:2.5606382E25)
            if (r0 == r1) goto L_0x0016
            goto L_0x0034
        L_0x0016:
            java.lang.String r0 = "shake_sensitivity"
            boolean r5 = r5.equals(r0)
            if (r5 == 0) goto L_0x0034
            r5 = 1
            goto L_0x0035
        L_0x0020:
            java.lang.String r0 = "Shake.Force"
            boolean r5 = r5.equals(r0)
            if (r5 == 0) goto L_0x0034
            r5 = 0
            goto L_0x0035
        L_0x002a:
            java.lang.String r0 = "shake_sensitivity_max"
            boolean r5 = r5.equals(r0)
            if (r5 == 0) goto L_0x0034
            r5 = 2
            goto L_0x0035
        L_0x0034:
            r5 = -1
        L_0x0035:
            if (r5 == 0) goto L_0x003f
            if (r5 == r3) goto L_0x003f
            if (r5 == r2) goto L_0x003c
            goto L_0x0042
        L_0x003c:
            r4.I()
        L_0x003f:
            r4.J()
        L_0x0042:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.touchprotector.features.shake.ShakeActivity.H(java.lang.String):void");
    }

    private void I() {
        float parseFloat = Float.parseFloat(biz.obake.team.touchprotector.g.a.l("shake_sensitivity"));
        float parseFloat2 = Float.parseFloat(biz.obake.team.touchprotector.g.a.l("shake_sensitivity_max"));
        int max = this.v.getMax() + 1;
        float f = (float) max;
        int round = Math.round((parseFloat * f) / parseFloat2);
        if (round < 1) {
            max = 1;
        } else if (round <= max) {
            max = round;
        }
        biz.obake.team.touchprotector.g.a.r("shake_sensitivity", String.format(Locale.US, "%.1f", new Object[]{Float.valueOf((parseFloat2 * ((float) max)) / f)}));
    }

    private void J() {
        float parseFloat = Float.parseFloat(biz.obake.team.touchprotector.g.c.c("Shake.Force"));
        long currentTimeMillis = System.currentTimeMillis();
        if (parseFloat > this.y || currentTimeMillis - this.x > 1000) {
            this.y = parseFloat;
            this.x = currentTimeMillis;
        }
        this.t.setText(biz.obake.team.touchprotector.c.w(R.string.pref_shake_sensitivity_sensor).replace("{0}", String.format(Locale.US, "%1.1f", new Object[]{Float.valueOf(this.y)})));
        String l = biz.obake.team.touchprotector.g.a.l("shake_sensitivity");
        float parseFloat2 = Float.parseFloat(l);
        String l2 = biz.obake.team.touchprotector.g.a.l("shake_sensitivity_max");
        float parseFloat3 = Float.parseFloat(l2);
        int max = this.v.getMax() + 1;
        boolean equals = "10.0".equals(l2);
        if (this.w.isChecked() != equals) {
            this.w.setChecked(equals);
        }
        this.u.setText(biz.obake.team.touchprotector.c.w(R.string.pref_shake_sensitivity_summary).replace("{0}", l));
        int round = Math.round((((float) max) * parseFloat2) / parseFloat3);
        if (round < 1) {
            max = 1;
        } else if (round <= max) {
            max = round;
        }
        this.v.setProgress(max - 1);
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.shake_sensitivity_activity);
        this.t = (TextView) findViewById(R.id.sensor);
        this.u = (TextView) findViewById(R.id.thresholdText);
        this.v = (SeekBar) findViewById(R.id.thresholdBar);
        this.w = (Switch) findViewById(R.id.expandMaxSwitch);
    }

    /* access modifiers changed from: protected */
    public void onPause() {
        super.onPause();
        this.v.setOnSeekBarChangeListener((SeekBar.OnSeekBarChangeListener) null);
        this.w.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener) null);
        biz.obake.team.touchprotector.g.a.i().unregisterOnSharedPreferenceChangeListener(this);
        biz.obake.team.touchprotector.g.c.h(this);
        biz.obake.team.touchprotector.g.c.f("Shake.Preview", false);
    }

    public void onRamPrefsChanged(String str) {
        H(str);
    }

    /* access modifiers changed from: protected */
    public void onResume() {
        super.onResume();
        this.v.setOnSeekBarChangeListener(new a());
        this.w.setOnCheckedChangeListener(new b(this));
        biz.obake.team.touchprotector.g.a.i().registerOnSharedPreferenceChangeListener(this);
        biz.obake.team.touchprotector.g.c.e(this);
        biz.obake.team.touchprotector.g.c.f("Shake.Preview", true);
        J();
    }

    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) {
        H(str);
    }
}
